//
//  WebViewController.m
//  MedicineBox
//
//  Created by dllo on 15/10/9.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ConsultWebViewController.h"
#import "DKNightVersion.h"
@interface ConsultWebViewController ()<UIWebViewDelegate>
@property (nonatomic, retain) UIWebView *webV;
@end

@implementation ConsultWebViewController
- (void)dealloc
{
    [_webV release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 60, 0, 60, 33)];
    titleLabel.text = @"资讯";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont fontWithName:@"Baskerville-SemiBold" size:20];
    self.navigationItem.titleView = titleLabel;
    [titleLabel release];

    [self createWeb];
}
- (void)createWeb
{
    self.webV = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 113)];
    _webV.delegate = self;
    _webV.nightBackgroundColor = UIColorFromRGB(0x343434);
    [_webV loadHTMLString:self.target baseURL:nil];
    [self.view addSubview:_webV];
    
    [_webV release];
    
    
//    _webV.paginationMode = UIWebPaginationModeTopToBottom;
    //_webV.paginationBreakingMode = UIWebPaginationBreakingModeColumn;
    
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [webView stringByEvaluatingJavaScriptFromString:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth;"
     "var maxwidth=375;" //缩放系数
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images[i];"
     "if(myimg.width > maxwidth){"
     "oldwidth = myimg.width;"
     "myimg.width = maxwidth;"
     "myimg.height = myimg.height * (maxwidth/oldwidth);"
     "}"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
